<%@ page import="com.cupk.entity.User" %><%--
  Created by IntelliJ IDEA.
  User: 17420
  Date: 2021/8/1
  Time: 10:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
    <script src="js/jquery.js"></script>
    <title>个人中心</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        b {
            font-weight: normal;
        }

        .box1 {
            margin-left: 30px;
        }

        .box1 div {
            margin: 10px 0;
            font-size: 16px;
        }

        .box2 {
            width: 500px;
        }

        .infos {
            margin: 20px;
        }

        .infos li {
            font-size: 15px;
            width: 600px;
            height: 80px;
            background-color: rgb(255, 253, 253);
            margin: 10px 0;
            border-radius: 5px;
            transition-duration: 0.1s;
            border: 1px solid #ddd;
            padding: 10px;
        }

        .infos li:hover {
            -webkit-box-shadow: #ccc 0px 10px 10px;
            -moz-box-shadow: #ccc 0px 10px 10px;
            box-shadow: #ccc 0px 10px 10px;
        }

        .infos .image {
            width: 60px;
            height: 80px;
            margin-right: 20px;
            float: left;
        }

        .infos .image img {
            width: 100%;
            height: 100%;
        }

        .infos a {
            height: 20px;
            color: #37a;
        }

        .infos button {
            float: right;
            margin-top: 20px;
        }

        .infos p {
            margin: 15px;
        }

        .pages {
            height: 50px;
            margin-left: 30px;
        }

        .pages b {
            height: 25px;
            width: 25px;
            display: block;
            float: left;
            border-radius: 15px;
            background-color: #fff;
            font-size: 12px;
            text-align: center;
            line-height: 25px;
            margin: 10px 5px;
            background-color: #ccc;
            cursor: pointer;
        }
    </style>
</head>

<body>
<ul class="layui-nav">

    <li class="layui-nav-item">
        <a href="#">个人中心</a>
    </li>
    <li class="layui-nav-item">
        <a href="index.jsp">回到首页</a>
    </li>
    <li class="layui-nav-item">
        <a href=""><img src="img/1.jpg" class="layui-nav-img">我</a>
        <dl class="layui-nav-child">
            <dd><a href="Logout">退出</a></dd>
        </dl>
    </li>

</ul>
<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">个人信息</li>
        <li>修改信息</li>
        <li>我的收藏</li>
        <li>评分记录</li>
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <div class="box1">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <i class="layui-icon layui-icon-username" style="font-size: 30px"></i> Info
                    </div>
                    <div class="layui-card-body">
                        <div class="name">昵称：<span>${user.getUsername()}</span></div>
                        <div class="id">用户ID：<span>${user.getId()}</span></div>
                        <div class="like">用户喜好：<span>${user.getHobbies()}</span></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-tab-item">
            <div class="box2">
                <form class="layui-form" action="Info?method=editInformation&userId=${user.getId()}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称:</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" required lay-verify="required" placeholder="请输入昵称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码:</label>
                        <div class="layui-input-inline">
                            <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-form-mid layui-word-aux">不少于6位</div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">偏好类型</label>
                        <div class="layui-input-block">
                            <select name="city" lay-verify="required">
                                <option value=""></option>
                                <option value="喜剧">喜剧</option>
                                <option value="爱情">爱情</option>
                                <option value="悬疑">悬疑</option>
                                <option value="动作">动作</option>
                                <option value="冒险">冒险</option>
                                <option value="科幻">科幻</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
        <div class="layui-tab-item">
            <ul class="infos">
                <c:forEach items="${collectible}" var="movie">
                <li>
                    <div class="image">
                        <img src="img/${movie.name}.webp">
                    </div>
                    <a class="name" href="Movie?method=findById&id=${movie.id}">${movie.name}<b class="year">${movie.year}</b></a>
                    <a href="Info?method=deleteCollect&movieId=${movie.id}&userId=${user.getId()}"> <button type="button" class="layui-btn layui-btn-primary layui-btn-sm">
                        <i class="layui-icon">&#xe640;</i></button></a>
                </li>
                </c:forEach>
            </ul>
            <div class="pages"></div>
        </div>
        <div class="layui-tab-item">
            <ul class="infos">
                <c:forEach items="${history}" var="historyMovie" >
                <li>
                    <div class="image">
                        <img src="img/${historyMovie.name}.webp">
                    </div>
                    <a class="name" href="Movie?method=findById&id=${historyMovie.id}">${historyMovie.name}<b class="year">${historyMovie.year}</b></a>
                    <p class="grade">我的评分：<b>${historyRate.get(historyMovie.id)}</b>星</p>
                </li>
                </c:forEach>
            </ul>
            <div class="pages"></div>
        </div>

    </div>
</div>

<script>
    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function() {
        var element = layui.element;

        //…
    });
    $(function() {
        var cur = 1; //当前页
        var pagesize = 10; //设置每页尺寸

        var renpage = function() {
            //定义函数，处理分页
            var x = (cur - 1) * pagesize;
            var y = cur * pagesize;
            $('.infos').find('li').hide().slice(x, y).show()
        }

        //以下代码添加分页
        var n = $('.infos').find('li').length; //总记录条数
        var pages = Math.ceil(n / pagesize); //计算总页数

        for (let p = 0; p < pages; p++) {
            $("<b>" + (p + 1) + "</b>").appendTo($('.pages')).click(function() {
                cur = p + 1;
                $('body,html').animate({
                        scrollTop: 0
                    },
                    100);
                renpage();
            });
        }

        renpage(); //当页面加载时也要初始化分页

    })
    window.onload = function() {
        //翻页高亮：
        var ele = document.querySelectorAll('.pages b');
        ele[0].style.backgroundColor = "#999";
        for (var i = 0; i < ele.length; i++) {
            ele[i].onclick = function() {
                for (var i = 0; i < ele.length; i++) {
                    ele[i].style.backgroundColor = "";
                }
                this.style.backgroundColor = '#999';
            }
        }
    }
</script>
</body>

</html>